package com.project.class8_23;

import java.util.ArrayList;
import java.util.Vector;

public class BankCode {
    private int money = 2000;
    public synchronized void takeMoney(int getMoney){
        if(this.money < getMoney){
            System.out.println("余额不足");
            return;
        }
        try {
            Thread.sleep(1000);
            this.money -= getMoney;
            System.out.println("取走"+getMoney+"   余额："+this.money);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        BankCode code = new BankCode();
        Man m1 = new Man(code,1500);
        Man m2 = new Man(code,1800);
    }
}

class Man extends Thread{
    private BankCode code;
    private int getMoney;
    public Man(BankCode code,int getMoney){
        this.code = code;
        this.getMoney = getMoney;
        this.start();
        ArrayList a;
        Vector v;
    }

    public void run(){
        code.takeMoney(getMoney);
    }
}
